package net.csdn.business.common.oauth2.service.impl;

import net.csdn.business.common.oauth2.mapper.OauthAuthLogMapper;
import net.csdn.business.common.domain.request.oauth.NewOauthAuthLogDTO;
import net.csdn.business.common.oauth2.model.entity.OauthAuthLog;
import net.csdn.business.common.domain.request.oauth.OauthAuthLogQuery;
import net.csdn.business.common.oauth2.service.IOauthAuthLogService;
import net.csdn.business.common.service.SnowflakeService;
import net.csdn.business.common.service.SuperServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * 应用授权明细Service业务层处理
 * 
 * @author zhangyl
 * @date 2022-11-16
 */
@Service
public class OauthAuthLogServiceImpl extends SuperServiceImpl<OauthAuthLogMapper, OauthAuthLog> implements IOauthAuthLogService
{

    @Autowired
    private SnowflakeService snowflakeService;

    @Override
    public Integer selectOauthAuthLogCount(OauthAuthLogQuery query) {
        return baseMapper.selectOauthAuthLogCount(query);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertOauthAuthLog(NewOauthAuthLogDTO newOauthAuthLog) {
        OauthAuthLog oauthAuthLog=new OauthAuthLog();
        BeanUtils.copyProperties(newOauthAuthLog, oauthAuthLog);
        oauthAuthLog.setObjectId(snowflakeService.nextNo());
        oauthAuthLog.setCreatedDate(new Date());
        baseMapper.insert(oauthAuthLog);
    }
}
